<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>
<script>
  const args = [4];
  fn = function (x) {
    return 2 * x;
  };
  var cancellable = function (fn, args, t) {
    fn(...args);
    const timeoutId = setInterval(() => {
      const returned = fn(...args);
      console.log({"time": timeoutId, "returned": returned});
    }, t);
   
    
    return function () {
      clearInterval(timeoutId);
    };
  };
  cancellable(fn, args, 35)
  
</script>
